import 'dart:convert' show json;

import 'package:x3_base_core/base_models/base_model_asT.dart';

class BaseHttpResponseModel {
  BaseHttpResponseModel({
    this.fieldName,
    this.name,
    this.notes,
    this.dataType,
    this.inputType,
    this.inputApi,
    this.inputRegex,
    this.showType,
    this.appDisplay,
    this.required,
    this.length,
    this.hidden,
    this.accessMode,
    this.width,
    this.position,
    this.columnLockType,
    this.webUrl,
    this.sort,
    this.costPrice,
    this.fontColor,
    this.columnBaseColor,
  });

  factory BaseHttpResponseModel.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : BaseHttpResponseModel(
          fieldName: asT<String>(jsonRes['fieldName']),
          name: asT<String>(jsonRes['name']),
          notes: asT<String>(jsonRes['notes']),
          dataType: asT<String>(jsonRes['dataType']),
          inputType: asT<String>(jsonRes['inputType']),
          inputApi: asT<String>(jsonRes['inputApi']),
          inputRegex: asT<String>(jsonRes['inputRegex']),
          showType: asT<String>(jsonRes['showType']),
          appDisplay: asT<String>(jsonRes['appDisplay']),
          required: asT<bool>(jsonRes['required']),
          length: asT<int>(jsonRes['length']),
          hidden: asT<bool>(jsonRes['hidden']),
          accessMode: asT<String>(jsonRes['accessMode']),
          width: asT<String>(jsonRes['width']),
          position: asT<int>(jsonRes['position']),
          columnLockType: asT<String>(jsonRes['columnLockType']),
          webUrl: asT<String>(jsonRes['webUrl']),
          sort: asT<bool>(jsonRes['sort']),
          costPrice: asT<bool>(jsonRes['costPrice']),
          fontColor: asT<String>(jsonRes['fontColor']),
          columnBaseColor: asT<String>(jsonRes['columnBaseColor']),
        );

  /// 名称 对应数据库的列名称
  String fieldName;

  /// 显示名称
  String name;

  /// 显示的宽度 以px结尾 或者是auto
  String width;

  /// 显示的最小宽度 以px结尾 或者是auto
  String minWidth;

  /// 显示的最大宽度 以px结尾 或者是auto
  String maxWidth;

  /// 格式化宽度
  double initWidth;

  /// 字段的类型
  String showType;

  /// 访问模式(只读 读写 隐藏)
  String accessMode;

  /// 请求的服务地址
  String inputApi;

  /// 提示内容
  String notes;

  /// 跳转地址
  String webUrl;

  /// 是否必填
  bool required;

  /// 是否可以排序
  bool sort;

  /// 是否隐藏
  bool hidden;

  /// 显示次序
  int position;

  /// app显示模版
  String appDisplay;

  String dataType;
  String inputType;
  String inputRegex;
  int length;
  String columnLockType;
  bool costPrice;
  String fontColor;
  String columnBaseColor;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'fieldName': fieldName,
        'name': name,
        'notes': notes,
        'dataType': dataType,
        'inputType': inputType,
        'inputApi': inputApi,
        'inputRegex': inputRegex,
        'showType': showType,
        'appDisplay': appDisplay,
        'required': required,
        'length': length,
        'hidden': hidden,
        'accessMode': accessMode,
        'width': width,
        'position': position,
        'columnLockType': columnLockType,
        'webUrl': webUrl,
        'sort': sort,
        'costPrice': costPrice,
        'fontColor': fontColor,
        'columnBaseColor': columnBaseColor,
      };

  @override
  String toString() {
    return json.encode(this);
  }

}
